** Data reading and variable selection from raw data
** Family Survey of the Dutch Population (Family-enquete Nederlandse Bevolking) 2000


** 01. Reading data **
cap log close
clear all
set more off
cd /*insert you work directory here*/
use /*read your data here*/ 


** 02. Consructing year and country variables **

ge year=2000
lab var year "survey year"

ge country=528
lab var country "ISO country code"
//Netherlands: 528 (see "ISO Country Codes.pdf) 


** 03. ID variables **

ge pid=respnr
lab var pid "respondent id"

ge fid=hhnr
lab var fid "family id"


** 04. Basic Demographics (Sex and Age/birth year) **

rename sex asex
recode asex (0=1 "male")(1=2 "female"),into(sex)
lab var sex "sex"

lab var age "age"

ge birthyr=year-age
lab var birthyr "year of birth"


** 05. Siblings **

ge nbro=c1
lab var nbro "number of brothers"
ge nsis=c2
lab var nsis "number of sisters"

ge nsibs=nbro+nsis
lab var nsibs "number of siblings"

forvalue i=1/15 {
rename c4_`i' sibsex`i'
rename c5_`i' sibyr`i'
}
recode sibsex* (0=.)
// sex of siblings are coded 0 when missing

ge nolderbro=0
ge noldersis=0
forvalue i=1/15 {
replace nolderbro=nolderbro+1 if sibsex`i'==1 & sibyr`i'>birthyr
replace noldersis=noldersis+1 if sibsex`i'==2 & sibyr`i'>birthyr
}
lab var nolderbro "number of older brothers"
lab var noldersis "number of older sisters"

ge birthorder=nolderbro+noldersis+1
lab var birthorder "birth order"


** 06. Own education **

//level of education
//Translated by Google
tab educlev
ge educ=educlev
lab var educ "level of education of the respondent"

lab def educ 1 "elementary school" 2 "lbo, huishoudschool, vbo" 3 "mavo, ulo, mulo" 4 "havo, mms" ///
5 "grammar school" 6 "kort mbo (kmbo)" 7 "volledig mbo" 8 "college/bachelor's degree" 9 "university" 10 "postgraduate"

lab val educ educ


** 07. Parents' education: Father and/or Mother **

//level of education
//Translated by Google
ge faeduc=b14
lab var faeduc "father's highest education obtained"
ge moeduc=b16
lab var moeduc "mother's highest education obtained"
lab val faeduc moeduc educ


** 08. Own occupation **

ge occ_CBS=cbs
lab var occ_CBS "current/last occupation cbs 1984 code"

ge occ_ISEI=sei
lab var occ_ISEI "respondent's occupation for current/last occupation in ISEI codes"

ge pre_US=us
lab var pre_US "prestige score for current/last occupation in US codes"

ge class_EGP=egp
lab var class_EGP "class for current/last occupation in EGP codes"

ge position=lmp
lab var lmp "current labour market position"


** 09. Parents' occupation **
//Translated by Google
//father
ge fawork=b18x
lab var fawork "if father's participating the labour market ever"
lab def fawork 1 "yes" 2 "no"
lab val fawork fawork

rename b18cbs faocc_CBS
lab var faocc_CBS "father now: current/last occupation cbs 1984 code"

rename b18sei faocc_ISEI
lab var faocc_ISEI "father now: occupation for current/last occupation in ISEI codes"

rename b18us fapre_US
lab var fapre_US "father now: prestige score for current/last occupation in US codes"

rename b18egp faclass_EGP
lab var faclass_EGP "father now: class for current/last occupation in EGP codes"

//industry categories do not have corresponding numbers
ge faind15=b19
lab var faind15 "father's industry when respondent is 15"

ge fasup15=b20
lab var fasup "father's supervising status when the respondent is 15 years"
lab def fasup 1 "no subordination" 2 "1-2 subordinate" 3 "3-10 subordinates" 4 "11-24 subordinates" 5 "25 or more subordinates"
lab val fasup fasup

ge faempstat15=b21
lab var faempstat15 "father's employment type when the respondent is 15 years"
lab def faempstat15 1 "employeed to business" 2 "employed (semi) government" 3 "own account/independent" 4 "family helper"
lab val faempstat15 faempstat15

//mother
ge moworkps=b22
lab var moworkps "if mother participated the labour market when the respondent was in pre-school"
lab def moworkps 1 "no" 2 "yes, less than 12 hours per week" 3 "yes, more than 12 hours per week"
lab val moworkps moworkps

ge moworkpri=b24
lab var moworkpri "if mother participated the labour market when the respondent was in primary school"
lab val moworkpri moworkps

ge mowork15=b26
lab var mowork15 "if mother participated the labour market when the respondent was 15 years"
lab val mowork15 moworkps

ge mowork=b22x
lab var mowork "if mother's participating the labour market ever"
lab def mowork 1 "yes" 2 "no"
lab val mowork mowork


** 10. Tabulate the Identified Variables **

log using /*insert you work directory here*/, replace text

** Data reading and variable selection from raw data
** Family Survey of the Dutch Population (Family-enquete Nederlandse Bevolking) 2000

** Sex **
tab sex

** Age, Birth Year **
sum age birthyr, d

** Siblings **
sum nsibs nbro nsis birthorder, d

** R's Own Education **
tab1 educ 

** Parental Education **
tab1 faeduc moeduc 

** R's Own Occupation **
tab1 occ_ISEI occ_CBS pre_US class_EGP position

** Parental Occupation **
tab1 fawork faocc_ISEI faocc_CBS fapre_US faclass_EGP faind15 fasup15 faempstat15 mowork moworkps moworkpri mowork15


log close

** 11. Keep the identified variables only

keep year country fid pid sex age birthyr ///
	 nsibs nbro nsis birthorder ///
	 educ faeduc moeduc ///
	 occ_ISEI occ_CBS pre_US class_EGP position ///
	 fawork faocc_ISEI faocc_CBS fapre_US faclass_EGP faind15 fasup15 faempstat15 mowork moworkps moworkpri mowork15


** 12. Save the Data File **

saveold /*insert you work directory here*/, replace



** 13. Homoginising education **
** Own Education **
rename educ educ_cat

ge educ_yrs=6 if educ_cat==1
replace educ_yrs=9 if educ_cat==2
replace educ_yrs=10 if educ_cat==3
replace educ_yrs=11 if educ_cat==4
replace educ_yrs=12 if educ_cat==5
replace educ_yrs=10 if educ_cat==6
replace educ_yrs=10.5 if educ_cat==7
replace educ_yrs=15 if educ_cat==8
replace educ_yrs=17 if educ_cat==9
replace educ_yrs=21 if educ_cat==10
lab var educ_yrs "respondent highest education in years"

ge educ_ISCED=100 if educ_cat==1
replace educ_ISCED=254 if educ_cat==2
replace educ_ISCED=244 if educ_cat==3
replace educ_ISCED=300 if educ_cat==4
replace educ_ISCED=300 if educ_cat==5
replace educ_ISCED=353 if educ_cat==6
replace educ_ISCED=354 if educ_cat==7
replace educ_ISCED=500 if educ_cat==8
replace educ_ISCED=600 if educ_cat==9
replace educ_ISCED=747 if educ_cat==10
lab var educ_ISCED "respondent highest education in ISCED code"

** Parents Education **
//father's education is actually father's
ge faeduc_flag=1 

rename faeduc faeduc_cat
rename moeduc maeduc_cat

ge faeduc_yrs=6 if faeduc_cat==1
replace faeduc_yrs=9 if faeduc_cat==2
replace faeduc_yrs=10 if faeduc_cat==3
replace faeduc_yrs=11 if faeduc_cat==4
replace faeduc_yrs=12 if faeduc_cat==5
replace faeduc_yrs=10 if faeduc_cat==6
replace faeduc_yrs=10.5 if faeduc_cat==7
replace faeduc_yrs=15 if faeduc_cat==8
replace faeduc_yrs=17 if faeduc_cat==9
replace faeduc_yrs=21 if faeduc_cat==10
lab var faeduc_yrs "father's education in years"

ge maeduc_yrs=6 if maeduc_cat==1
replace maeduc_yrs=9 if maeduc_cat==2
replace maeduc_yrs=10 if maeduc_cat==3
replace maeduc_yrs=11 if maeduc_cat==4
replace maeduc_yrs=12 if maeduc_cat==5
replace maeduc_yrs=10 if maeduc_cat==6
replace maeduc_yrs=10.5 if maeduc_cat==7
replace maeduc_yrs=15 if maeduc_cat==8
replace maeduc_yrs=17 if maeduc_cat==9
replace maeduc_yrs=21 if maeduc_cat==10
lab var maeduc_yrs "mother's education in years"

ge faeduc_ISCED=100 if faeduc_cat==1
replace faeduc_ISCED=254 if faeduc_cat==2
replace faeduc_ISCED=244 if faeduc_cat==3
replace faeduc_ISCED=300 if faeduc_cat==4
replace faeduc_ISCED=300 if faeduc_cat==5
replace faeduc_ISCED=353 if faeduc_cat==6
replace faeduc_ISCED=354 if faeduc_cat==7
replace faeduc_ISCED=500 if faeduc_cat==8
replace faeduc_ISCED=600 if faeduc_cat==9
replace faeduc_ISCED=747 if faeduc_cat==10
lab var faeduc_ISCED "father highest education in ISCED code"

ge maeduc_ISCED=100 if maeduc_cat==1
replace maeduc_ISCED=254 if maeduc_cat==2
replace maeduc_ISCED=244 if maeduc_cat==3
replace maeduc_ISCED=300 if maeduc_cat==4
replace maeduc_ISCED=300 if maeduc_cat==5
replace maeduc_ISCED=353 if maeduc_cat==6
replace maeduc_ISCED=354 if maeduc_cat==7
replace maeduc_ISCED=500 if maeduc_cat==8
replace maeduc_ISCED=600 if maeduc_cat==9
replace maeduc_ISCED=747 if maeduc_cat==10
lab var maeduc_ISCED "mother highest education in ISCED code"

** 14. Homoginising sibling **
//cutoff
ge nsibs_flag=99
lab var nsibs_flag "cutoff of total number of siblings"
ge nsis_flag=99
lab var nsis_flag "cutoff of number of sisters"
ge nbro_flag=99
lab var nbro_flag "cutoff of number of brothers"

lab def nsib_flag 99 "no cutoff"
lab val nsis_flag nbro_flag nsibs_flag nsib_flag


** 15. Tab Education and Sibling Variables **
tab1 sex age birthyr
tab1 educ_cat educ_yrs faeduc_cat faeduc_yrs maeduc_cat maeduc_yrs faeduc_flag 
tab1 nsis nbro nsibs nsis_flag nbro_flag nsibs_flag


** 16. Save the Data File **

saveold /*insert you work directory here*/, replace
